package testes.vSys.util;

import java.text.DecimalFormat;
import java.util.Locale;

import org.apache.struts.util.MessageResources;

public final class Utilities {

	public static String getMessage(String key){
		return MessageResources.getMessageResources("MessageResources").getMessage(Locale.getDefault(),key);
	}
	
	public static String getMessage(String key, String parameter){
		return MessageResources.getMessageResources("MessageResources").getMessage(Locale.getDefault(),key,parameter);
	}
	
	public static String getFormattedCurrency(String value){
		
		float numericValue = Float.valueOf(value);
		DecimalFormat decimalFormat = new DecimalFormat("#,##0.00;(#,##0.00)");
		return decimalFormat.format(numericValue);
	}
	
	public static boolean validateRequired(String field){
		
		if ((field == null) || ("".equals(field)))
			return false;
		
		return true;
	}
	
	public static boolean validateNumeric(String field){
		
		try{
			Long.parseLong(field);
			return true;
		}catch(Exception e){
			return false;
		}
	}

	public static boolean validateReal(String field){
		
		try{
			Float.parseFloat(field);
			return true;
		}catch(NumberFormatException e){
			return false;
		}
	}

	
}
